/*
 * Copyright (C) 2011 Mette Bank, Rikke Jensen, Kenneth Brodersen, Thomas Pedersen
 * 
 * This file is part of digiPECS.
 * 
 * digiPECS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * digiPECS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with digiPECS.  If not, see <http://www.gnu.org/licenses/>.
 */

package sw6.digipecs.widget.admin;

import sw6.digipecs.R;
import sw6.digipecs.model.ExtImage;
import sw6.digipecs.widget.ExtImageView;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

public class SelectableExtImageView extends FrameLayout {

	private ExtImageView mExtImageView;
	private ImageView mAddImageView;

	private boolean mSelected = false;
	private ImageView mDeleteImageView;
	private ImageView mInActiveImageView;

	public SelectableExtImageView(Context context) {
		super(context);
		initialise();
	}

	public SelectableExtImageView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initialise();
	}

	private void initialise() {
		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li;
		li = (LayoutInflater) getContext().getSystemService(infService);
		li.inflate(R.layout.selectableextimagelayout, this, true);
		mExtImageView = (ExtImageView) findViewById(R.id.selectableExtImage);
		mAddImageView = (ImageView) findViewById(R.id.selectableAddImage);
		mDeleteImageView = (ImageView) findViewById(R.id.selectableDeleteImage);
		mInActiveImageView = (ImageView) findViewById(R.id.selectableActiveImage);
		
		mAddImageView.setVisibility(View.GONE); 
		mDeleteImageView.setVisibility(View.GONE); 
	}

	public void setExtImage(ExtImage extImage, int selectmode) {
		mExtImageView.setImage(extImage);
		mSelected = extImage.isSelected();
		if (mSelected) {
			switch (selectmode) {
			case SelectableExtImageAdapter.SELECT_MODE_ADD:
				mAddImageView.setVisibility(View.VISIBLE);
				break;
			case SelectableExtImageAdapter.SELECT_MODE_DELETE:
				mDeleteImageView.setVisibility(View.VISIBLE);
				break;
			case SelectableExtImageAdapter.SELECT_MODE_ACTIVE:
				mInActiveImageView.setVisibility(View.GONE); 
				break;
			}
		} else {
			mAddImageView.setVisibility(View.GONE);
			mDeleteImageView.setVisibility(View.GONE);
			if(selectmode==SelectableExtImageAdapter.SELECT_MODE_ACTIVE)
				mInActiveImageView.setVisibility(View.VISIBLE);
			else 
				mInActiveImageView.setVisibility(View.GONE); 
		}

	}
}
